<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016-7-21
 * Time: 10:12
 */

if ($_SERVER["REQUEST_METHOD"] == "POST") {
//    echo json_encode(array("111"=>"112"));
    if (isset($_POST["url"]) && isset($_POST["username"]) && isset($_POST["password"])) {
        $result = postDemo($_POST["url"], array("username" => $_POST["username"], "password" => $_POST["password"]));
        echo $result;

    } else {
        echo json_encode(array("msg2" => "!!!!!!!!!!!!!!!!!!!!!error!!!!!2"));
    }
} else {
    echo json_encode(array("msg" => "error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
}
function postDemo($url, $data)
{

    $query = http_build_query($data);
    $options = array(
        "http" => array(
            "header" => "Content-type: application/x-www-form-urlencoded\r\n" .
                "Content-length:" . strlen($query) . "\r\n" .
                "User-Agent:MyAgent/1.0/r/n",
            "method" => "POST",
            "content" => $query
        )
    );
    $content = stream_context_create($options);
    $result = file_get_contents($url, false, $content);
    return $result;
}